﻿#include <cstdint>
#include "PlatformProperty.h"
#include "SignalManager.h"
#include "ap/signal_id.h"
#include <OpHmiSeatClimaStructUtil.h>

// 主驾超时反馈
#define HVAC_SEAT_VENTILATION_MSG_1 1011
// 副驾超时反馈
#define HVAC_SEAT_VENTILATION_MSG_2 1012
// 二排左超时反馈
#define HVAC_SEAT_VENTILATION_MSG_3 1013
// 二排右超时反馈
#define HVAC_SEAT_VENTILATION_MSG_4 1014
// 副驾关闭通风、关闭档位
#define HVAC_SEAT_VENTILATION_PASS_NB 1015
// 二排左关闭通风、关闭档位
#define HVAC_SEAT_VENTILATION_SEC_LE_NB 1017
// 二排右关闭通风、关闭档位
#define HVAC_SEAT_VENTILATION_SEC_RI_NB 1019

#define HVAC_DELAY 3 * 1000

#define VENT_TIME 59

namespace ecarx::vhal::core::property::impl { class VehiclePropertyHVAC_SEAT_VENTILATION; }

static sdb::UsgModSts1 lastUsgMode = sdb::UsgModSts1::UsgModAbdnd;

bool hasSendVentTmr = false;

// 副驾无人乘坐时间计时
std::chrono::time_point<std::chrono::steady_clock> mSVentPassStart, mSVentPassEnd;
// 第二排左边无人乘坐时间计时
std::chrono::time_point<std::chrono::steady_clock> mSVentSecLeStart, mSVentSecLeEnd;
// 第二排右边无人乘坐时间计时
std::chrono::time_point<std::chrono::steady_clock> mSVentSecRiStart, mSVentSecRiEnd;

// 是否座椅上无人计时中
bool mIsSVentPassCounting = false;
bool mIsSVentSecLeCounting = false;
bool mIsSVentSecRiCounting = false;

// 是否等待反馈中
static bool mIsWaitingMsg1 = false;
static bool mIsWaitingMsg2 = false;
static bool mIsWaitingMsg3 = false;
static bool mIsWaitingMsg4 = false;

// 设置请求值缓存
int32_t g_ventDrvrReqValue = NONE;
int32_t g_ventPassReqValue = NONE;
int32_t g_ventSecLeReqValue = NONE;
int32_t g_ventSecRiReqValue = NONE;

static void removeMessage(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, uint32_t msgId);

static void sendMessage(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, uint32_t msgId, int32_t value);

static bool isWaiting(int32_t msgId) {
    switch (msgId)
    {
    case HVAC_SEAT_VENTILATION_MSG_1:
        return mIsWaitingMsg1;
    case HVAC_SEAT_VENTILATION_MSG_2:
        return mIsWaitingMsg2;
    case HVAC_SEAT_VENTILATION_MSG_3:
        return mIsWaitingMsg3;
    case HVAC_SEAT_VENTILATION_MSG_4:
        return mIsWaitingMsg4;
    }
    return false;
}

static void setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1 onOff1) {
    if (onOff1 == sdb::OnOff1::Off) {
        VHALOG.d("HVAC_SEAT_VENTILATION setCB_VFC_SeatClimaForHmiCenPDC OFF");
        SIGNAL.setCB_VFC_SeatClimaForHmiCenPDC(onOff1);
    } else if (SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModCnvinc)) {
        VHALOG.d("HVAC_SEAT_VENTILATION setCB_VFC_SeatClimaForHmiCenPDC ON");
        SIGNAL.setCB_VFC_SeatClimaForHmiCenPDC(onOff1);
    }
}

VehicleAreaSeat getSVentDrvrArea() {
    return (isLeftRudder() ? VehicleAreaSeat::ROW_1_LEFT : VehicleAreaSeat::ROW_1_RIGHT);
}

VehicleAreaSeat getSVentPassArea() {
    return (isLeftRudder() ? VehicleAreaSeat::ROW_1_RIGHT : VehicleAreaSeat::ROW_1_LEFT);
}

void offSeatVentnCheck(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, bool offDriver,
        bool offPass, bool offSecLe, bool offSecRi);

void setDriverSeatVentn(int32_t drvrlvl) {
    g_ventDrvrReqValue = drvrlvl;
    setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::On);
    OpHmiSeatClima_SetRequestNoReturn climaValue = getCurrOpHmiSeatClima();
    if (isLeftRudder()) {
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstLe = (uint8_t)mappingValue(drvrlvl, sdb::SeatClimaLvl::Off);
    } else {
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstRi = (uint8_t)mappingValue(drvrlvl, sdb::SeatClimaLvl::Off);
    }
    SIGNAL.setHmiSeatClima(climaValue);
}

void setPassSeatVentn(int32_t passlvl) {
    g_ventPassReqValue = passlvl;
    setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::On);
    OpHmiSeatClima_SetRequestNoReturn climaValue = getCurrOpHmiSeatClima();
    if (isLeftRudder()) {
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstRi = (uint8_t)mappingValue(passlvl, sdb::SeatClimaLvl::Off);
    } else {
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstLe = (uint8_t)mappingValue(passlvl, sdb::SeatClimaLvl::Off);
    }
    SIGNAL.setHmiSeatClima(climaValue);
}

void setSecLeSeatVentn(int32_t secLelvl) {
    g_ventSecLeReqValue = secLelvl;
    setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::On);
    OpHmiSeatClima_SetRequestNoReturn climaValue = getCurrOpHmiSeatClima();
    climaValue.hmiSeatClimaHmiSeatVentnForRowSecLe = (uint8_t)mappingValue(secLelvl, sdb::SeatClimaLvl::Off);
    SIGNAL.setHmiSeatClima(climaValue);
}

void setSecRiSeatVentn(int32_t secRilvl) {
    g_ventSecRiReqValue = secRilvl;
    setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::On);
    OpHmiSeatClima_SetRequestNoReturn climaValue = getCurrOpHmiSeatClima();
    climaValue.hmiSeatClimaHmiSeatVentnForRowSecRi = (uint8_t)mappingValue(secRilvl, sdb::SeatClimaLvl::Off);
    SIGNAL.setHmiSeatClima(climaValue);
}

PropertyStatus getSeatVentDriverStatus()
{
    auto chrSt = SIGNAL.getOnBdChrgrSt();
    if (SIGNAL.carConfigIs(SignalRX::carconfig179, sdb::CarConfig179::_02,
                            sdb::CarConfig179::_03, sdb::CarConfig179::_80,
                            sdb::CarConfig179::_81, sdb::CarConfig179::_82,
                            sdb::CarConfig179::_83, sdb::CarConfig179::_84)) {
        if (SIGNAL.getDrvrSeatVentAvlSts() == sdb::StsFd::Functionallimit) {
            return PropertyStatus::NotActive;
        }
        if ((SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_01, sdb::CarConfig13::_02, sdb::CarConfig13::_80)) &&
            SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg) &&
            SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm,
                                sdb::CarModSts1::CarModDyno)) {
            return PropertyStatus::Active;
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_03)
            && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno))
        {
            if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg))
            {
                return PropertyStatus::Active;
            }
            else if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModCnvinc) && chrSt == sdb::ChrgrSts1::Chrgn)
            {
                return PropertyStatus::Active;
            }
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04) && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno)
            && SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg, sdb::UsgModSts1::UsgModCnvinc, sdb::UsgModSts1::UsgModActv))
        {
            return PropertyStatus::Active;
        }

        return PropertyStatus::NotActive;
    }
    return PropertyStatus::NotAvailable;
}

PropertyStatus getSeatVentPassStatus() {
    auto chrSt = SIGNAL.getOnBdChrgrSt();
    if (SIGNAL.carConfigIs(SignalRX::carconfig179, sdb::CarConfig179::_02,
                            sdb::CarConfig179::_03, sdb::CarConfig179::_80,
                            sdb::CarConfig179::_81, sdb::CarConfig179::_82,
                            sdb::CarConfig179::_83, sdb::CarConfig179::_84)) {
        if (SIGNAL.getPassSeatVentAvlSts() == sdb::StsFd::Functionallimit) {
            return PropertyStatus::NotActive;
        }
        if ((SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_01, sdb::CarConfig13::_02, sdb::CarConfig13::_80)) &&
            SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg) &&
            SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm,
                                sdb::CarModSts1::CarModDyno)) {
            return PropertyStatus::Active;
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_03)
            && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno))
        {
            if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg))
            {
                return PropertyStatus::Active;
            }
            else if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModCnvinc) && chrSt == sdb::ChrgrSts1::Chrgn)
            {
                return PropertyStatus::Active;
            }
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04) && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno)
            && SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg, sdb::UsgModSts1::UsgModCnvinc, sdb::UsgModSts1::UsgModActv))
        {
            return PropertyStatus::Active;
        }

        return PropertyStatus::NotActive;
    }
    return PropertyStatus::NotAvailable;
}

PropertyStatus getSeatVentSecLeStatus(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr);

PropertyStatus getSeatVentSecRiStatus(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr);

void sendSeatVentTmr() {
    if (!SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModAbdnd)) {
        VHALOG.d("HVAC_SEAT_VENTILATION setCB_VFC_MmedbtnifClimate On");
        SIGNAL.setCB_VFC_MmedbtnifClimate(sdb::OnOff1::On);
    }
    OpHmiSeatClimaTmr_SetRequestNoReturn climateTmrValue;
    climateTmrValue.hmiSeatClimaTmrHmiSeatHeatgFirstLeTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatHeatgFirstRiTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatHeatgSecLeTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatHeatgSecRiTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatVentnFirstLeTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatVentnFirstRiTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatVentnSecLeTmr = VENT_TIME;
    climateTmrValue.hmiSeatClimaTmrHmiSeatVentnSecRiTmr = VENT_TIME;
    SIGNAL.setHmiSeatClimaTmr(climateTmrValue);
}

void checkSVentCountdown(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, VehicleAreaSeat area, bool &isCounting,
        std::chrono::time_point<std::chrono::steady_clock> &start, std::chrono::time_point<std::chrono::steady_clock> &end);

void clearSVentCountdown(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, VehicleAreaSeat area);

PropertyStatus withStatusBySignalsSVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr);

PropertyStatus withStatusBySignalsSVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr);

int32_t withValueBySignalsSVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& last);

int32_t withValueBySignalsSVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& last);

void onSetPropertySVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& value);

void onSetPropertySVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& value);

//[SW_FC_003_028] 座椅通风功能SeatVent
SYSTEM_READ_WRITE_PROPERTY(HVAC_SEAT_VENTILATION, int32_t) {
    builder.area(VehicleAreaSeat::ROW_1_LEFT)
        .initValue([]() { return SEAT_CLIMA_OFF; })
        .withStatusBySignals(
            [this]([[maybe_unused]] const PropertyStatus& lastStatus) {
                if (isLeftRudder()) {
                    return withStatusBySignalsSVentDrvr(this);
                }
                return withStatusBySignalsSVentPass(this);
            },
            SignalRX::carconfig179,
            SignalRX::carconfig189,
            SignalRX::carconfig13,
            SignalRX::VehModMngtGlbSafe1UsgModSts,
            SignalRX::VehModMngtGlbSafe1CarModSts1,
            SignalRX::RowFrstPassODSSts,
            SignalRX::PassSeatVentnLvlSts,
            SignalRX::DrvrSeatVentAvlSts,
            SignalRX::PassSeatVentAvlSts)
        .withValueBySignals(
            [this]([[maybe_unused]] const int32_t& last) {
                 if (isLeftRudder()) {
                    return withValueBySignalsSVentDrvr(this, last);
                }
                return withValueBySignalsSVentPass(this, last);
            }, SignalRX::PassSeatVentnLvlSts,
            SignalRX::DrvrSeatVentnLvlSts)
        .onSetProperty([this](const int32_t& value) {
            if (isLeftRudder()) {
                onSetPropertySVentDrvr(this, value);
            } else {
                onSetPropertySVentPass(this, value);
            }
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_MSG_1, [this]() {
            removeMessage(this, HVAC_SEAT_VENTILATION_MSG_1);
            // 3s后根据反馈信号更新
            setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::Off);

            auto sdbValue = mappingValue(SIGNAL.getDrvrSeatVentnLvlSts(), SEAT_CLIMA_OFF);

            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_MSG_1: g_ventDrvrReqValue:%d, sdbValue: %d", g_ventDrvrReqValue, sdbValue);
            if (g_ventDrvrReqValue != sdbValue) {
                g_ventDrvrReqValue = sdbValue;
                setDriverSeatVentn(g_ventDrvrReqValue);
            }
            setValue(toInt(getSVentDrvrArea()), g_ventDrvrReqValue, false);
        })
        .area(VehicleAreaSeat::ROW_1_RIGHT)
        .initValue([]() { return SEAT_CLIMA_OFF; })
        .withStatusBySignals([this]([[maybe_unused]] const PropertyStatus& lastStatus) {
            if (isLeftRudder()) {
                return withStatusBySignalsSVentPass(this);
            }
            return withStatusBySignalsSVentDrvr(this);
        },
        SignalRX::carconfig179,
        SignalRX::carconfig189,
        SignalRX::carconfig13,
        SignalRX::VehModMngtGlbSafe1UsgModSts,
        SignalRX::VehModMngtGlbSafe1CarModSts1,
        SignalRX::RowFrstPassODSSts,
        SignalRX::PassSeatVentnLvlSts,
        SignalRX::DrvrSeatVentAvlSts,
        SignalRX::PassSeatVentAvlSts)
        .withValueBySignals([this]([[maybe_unused]] const int32_t& last) {
            if (isLeftRudder()) {
                return withValueBySignalsSVentPass(this, last);
            }
            return withValueBySignalsSVentDrvr(this, last);
        }, SignalRX::PassSeatVentnLvlSts,
        SignalRX::DrvrSeatVentnLvlSts)
        .onSetProperty([this](const int32_t& value) {
            if (isLeftRudder()) {
                onSetPropertySVentPass(this, value);
            } else {
                onSetPropertySVentDrvr(this, value);
            }
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_MSG_2, [this]() {
            removeMessage(this, HVAC_SEAT_VENTILATION_MSG_2);
            // 3s后根据反馈信号更新
            setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::Off);

            auto sdbValue = mappingValue(SIGNAL.getPassSeatVentnLvlSts(), SEAT_CLIMA_OFF);

            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_MSG_2: g_ventPassReqValue:%d, sdbValue: %d", g_ventPassReqValue, sdbValue);
            if (g_ventPassReqValue != sdbValue) {
                g_ventPassReqValue = sdbValue;
                setPassSeatVentn(g_ventPassReqValue);
            }
            setValue(toInt(getSVentPassArea()), g_ventPassReqValue, false);
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_PASS_NB, []() {
            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_PASS_NB ");
            setPassSeatVentn(SEAT_CLIMA_OFF);
        })
        .area(VehicleAreaSeat::ROW_2_LEFT)
        .initValue([]() { return SEAT_CLIMA_OFF; })
        .withStatusBySignals([this]([[maybe_unused]] const PropertyStatus& lastStatus) {
            VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_LEFT cc189[%d],cc13[%d],usgMod[%d],carMod[%d],secLeAvlSts[%d]",
                  SIGNAL.getcarconfig189(), SIGNAL.getcarconfig13(), SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                  SIGNAL.getSeatVentAvlStsRowSecLe());
            checkSVentCountdown(this, VehicleAreaSeat::ROW_2_LEFT, mIsSVentSecLeCounting, mSVentSecLeStart, mSVentSecLeEnd);
            return getSeatVentSecLeStatus(this);
        },
        SignalRX::carconfig189,
        SignalRX::carconfig13,
        SignalRX::VehModMngtGlbSafe1UsgModSts,
        SignalRX::VehModMngtGlbSafe1CarModSts1,
        SignalRX::RowSecLeODSSts,
        SignalRX::SeatVentnLvlStsRowSecLe,
        SignalRX::SeatVentAvlStsRowSecLe)
        .withValueBySignals([]([[maybe_unused]] const int32_t& last) {
            if (isWaiting(HVAC_SEAT_VENTILATION_MSG_3)) {
                VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_LEFT isWaiting HVAC_SEAT_VENTILATION_MSG_3 return.");
                return last;
            }
            sdb::SeatClimaLvl sdblvl = SIGNAL.getSeatVentnLvlStsRowSecLe();
            auto hallvl = mappingValue(sdblvl, SEAT_CLIMA_OFF);
            g_ventSecLeReqValue = hallvl;
            VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_LEFT value sdblvl : %d , hallvl:%d ", toInt(sdblvl), hallvl);
            return hallvl;
        }, SignalRX::SeatVentnLvlStsRowSecLe)
        .onSetProperty([this](const int32_t& value) {
            VHALOG.d("halOnSetProperty HVAC_SEAT_VENTILATION ROW_2_LEFT value: %d", value);

            if (value != SEAT_CLIMA_OFF &&
                value != SEAT_CLIMA_LEVEL_1 &&
                value != SEAT_CLIMA_LEVEL_2 &&
                value != SEAT_CLIMA_LEVEL_3) {
                VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_LEFT: param invalid");
                return;
            }
            if (mappingValue(SIGNAL.getSeatVentnLvlStsRowSecLe(), SEAT_CLIMA_OFF) == value) {
                return;
            }
            clearSVentCountdown(this, VehicleAreaSeat::ROW_2_LEFT);
            sendMessage(this, HVAC_SEAT_VENTILATION_MSG_3, value);
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_MSG_3, [this]() {
            removeMessage(this, HVAC_SEAT_VENTILATION_MSG_3);
            // 3s后根据反馈信号更新
            setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::Off);

            auto sdbValue = mappingValue(SIGNAL.getSeatVentnLvlStsRowSecLe(), SEAT_CLIMA_OFF);

            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_MSG_3: g_ventSecLeReqValue:%d, sdbValue: %d", g_ventSecLeReqValue, sdbValue);
            if (g_ventSecLeReqValue != sdbValue) {
                g_ventSecLeReqValue = sdbValue;
                setSecLeSeatVentn(g_ventSecLeReqValue);
            }
            setValue(toInt(VehicleAreaSeat::ROW_2_LEFT), g_ventSecLeReqValue, false);
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_SEC_LE_NB, []() {
            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_SEC_LE_NB ");
            setSecLeSeatVentn(SEAT_CLIMA_OFF);
        })
        .area(VehicleAreaSeat::ROW_2_RIGHT)
        .initValue([]() { return SEAT_CLIMA_OFF; })
        .withStatusBySignals([this]([[maybe_unused]] const PropertyStatus& lastStatus) {
            VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_RIGHT cc189[%d],cc13[%d],usgMod[%d],carMod[%d],secRiAvlSts[%d]",
                  SIGNAL.getcarconfig189(), SIGNAL.getcarconfig13(), SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                  SIGNAL.getSeatVentAvlStsRowSecRi());
           checkSVentCountdown(this, VehicleAreaSeat::ROW_2_RIGHT, mIsSVentSecRiCounting, mSVentSecRiStart, mSVentSecRiEnd);
           return getSeatVentSecRiStatus(this);
        },
        SignalRX::carconfig189,
        SignalRX::carconfig13,
        SignalRX::VehModMngtGlbSafe1UsgModSts,
        SignalRX::VehModMngtGlbSafe1CarModSts1,
        SignalRX::RowSecRiODSSts,
        SignalRX::SeatVentnLvlStsRowSecRi,
        SignalRX::SeatVentAvlStsRowSecRi)
        .withValueBySignals([]([[maybe_unused]] const int32_t& last) {
            if (isWaiting(HVAC_SEAT_VENTILATION_MSG_4)) {
                VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_RIGHT isWaiting HVAC_SEAT_VENTILATION_MSG_4 return.");
                return last;
            }
            sdb::SeatClimaLvl sdblvl = SIGNAL.getSeatVentnLvlStsRowSecRi();
            auto hallvl = mappingValue(sdblvl, SEAT_CLIMA_OFF);
            g_ventSecRiReqValue = hallvl;
            VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_RIGHT value sdblvl : %d , hallvl:%d ", toInt(sdblvl), hallvl);
            return hallvl;
        }, SignalRX::SeatVentnLvlStsRowSecRi)
        .onSetProperty([this](const int32_t& value) {
            VHALOG.d("halOnSetProperty HVAC_SEAT_VENTILATION ROW_2_RIGHT value: %d", value);

            if (value != SEAT_CLIMA_OFF &&
                value != SEAT_CLIMA_LEVEL_1 &&
                value != SEAT_CLIMA_LEVEL_2 &&
                value != SEAT_CLIMA_LEVEL_3) {
                VHALOG.d("HVAC_SEAT_VENTILATION ROW_2_RIGHT: param invalid");
                return;
            }

            if (mappingValue(SIGNAL.getSeatVentnLvlStsRowSecRi(), SEAT_CLIMA_OFF) == value) {
                return;
            }
            clearSVentCountdown(this, VehicleAreaSeat::ROW_2_RIGHT);
            sendMessage(this, HVAC_SEAT_VENTILATION_MSG_4, value);
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_MSG_4, [this]() {
            removeMessage(this, HVAC_SEAT_VENTILATION_MSG_4);
            // 3s后根据反馈信号更新
            setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::Off);

            auto sdbValue = mappingValue(SIGNAL.getSeatVentnLvlStsRowSecRi(), SEAT_CLIMA_OFF);

            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_MSG_4: g_ventSecRiReqValue:%d, sdbValue: %d", g_ventSecRiReqValue, sdbValue);
            if (g_ventSecRiReqValue != sdbValue) {
                g_ventSecRiReqValue = sdbValue;
                setSecRiSeatVentn(g_ventSecRiReqValue);
            }
            setValue(toInt(VehicleAreaSeat::ROW_2_RIGHT), g_ventSecRiReqValue, false);
        })
        .onMsgEvent(HVAC_SEAT_VENTILATION_SEC_RI_NB, []() {
            VHALOG.d("halOnMsgEvent HVAC_SEAT_VENTILATION HVAC_SEAT_VENTILATION_SEC_RI_NB ");
            setSecRiSeatVentn(SEAT_CLIMA_OFF);
        });
}

void checkSVentCountdown(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, VehicleAreaSeat area, bool &isCounting,
        std::chrono::time_point<std::chrono::steady_clock> &start, std::chrono::time_point<std::chrono::steady_clock> &end) {
    if (thisPtr == nullptr) {
        VHALOG.d("HVAC_SEAT_VENTILATION checkSVentCountdown this is null");
        return;
    }
    uint32_t msgIdNB = 0;
    sdb::OccptPresSt1 odsSts = sdb::OccptPresSt1::Undefd1;
    sdb::SeatClimaLvl sdblvl = sdb::SeatClimaLvl::Off;
    if (area == getSVentPassArea()) {
        msgIdNB = HVAC_SEAT_VENTILATION_PASS_NB;
        odsSts = SIGNAL.getRowFrstPassODSSts();
        sdblvl = SIGNAL.getPassSeatVentnLvlSts();
    } else if (area == VehicleAreaSeat::ROW_2_LEFT) {
        msgIdNB = HVAC_SEAT_VENTILATION_SEC_LE_NB;
        odsSts = SIGNAL.getRowSecLeODSSts();
        sdblvl = SIGNAL.getSeatVentnLvlStsRowSecLe();
    } else {
        msgIdNB = HVAC_SEAT_VENTILATION_SEC_RI_NB;
        odsSts = SIGNAL.getRowSecRiODSSts();
        sdblvl = SIGNAL.getSeatVentnLvlStsRowSecRi();
    }

    int32_t nobdLcfg = lcfg::LocalConfig::getInstance().getInt<int32_t>(lcfg::LCFG_CountdownofVentilationNobody);
    int32_t curHalValue = thisPtr->getPropertyValue<int32_t>(
                static_cast<int32_t>(VehicleProperty::HVAC_SEAT_VENTILATION),
                static_cast<int32_t>(area));
    VHALOG.d("HVAC_SEAT_VENTILATION checkSVentCountdown : %d, msgIdNB: %d, odsSts: %d, sdblvl: %d, nobdLcfg: %d, curHalValue: %d",
            area, msgIdNB, odsSts, sdblvl, nobdLcfg, curHalValue);
    if (!isCounting && sdblvl !=  sdb::SeatClimaLvl::Off && odsSts == sdb::OccptPresSt1::OccptNotPrsnt) {
         VHALOG.d("HVAC_SEAT_VENTILATION checkSVentCountdown : start countdown");
        isCounting = true;
        start = std::chrono::steady_clock::now();
        thisPtr->sendMsg(msgIdNB, nobdLcfg * 1000);
    } else if (isCounting && curHalValue !=  SEAT_CLIMA_OFF && odsSts == sdb::OccptPresSt1::OccptPrsnt) {
        end = std::chrono::steady_clock::now();
        std::chrono::duration<float> duration = end - start;
        VHALOG.d("HVAC_SEAT_VENTILATION checkSVentCountdown: %d, duration: %f", area, duration.count());
        if (duration.count() < nobdLcfg) {
            clearSVentCountdown(thisPtr, area);
        }
    }
}

void clearSVentCountdown(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, VehicleAreaSeat area) {
    if (area == getSVentPassArea()) {
        mIsSVentPassCounting = false;
        thisPtr->removeMsg(HVAC_SEAT_VENTILATION_PASS_NB);
    } else if (area == VehicleAreaSeat::ROW_2_LEFT) {
        mIsSVentSecLeCounting = false;
        thisPtr->removeMsg(HVAC_SEAT_VENTILATION_SEC_LE_NB);
    } else {
        mIsSVentSecRiCounting = false;
        thisPtr->removeMsg(HVAC_SEAT_VENTILATION_SEC_RI_NB);
    }
}

PropertyStatus withStatusBySignalsSVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr) {
    VHALOG.d("HVAC_SEAT_VENTILATION DRVR cc179[%d],cc13[%d],usgMod[%d],carMod[%d], drvrAvlSts[%d]",
                      SIGNAL.getcarconfig179(), SIGNAL.getcarconfig13(), SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
                      SIGNAL.getDrvrSeatVentAvlSts());

    auto usgmod = SIGNAL.getVehModMngtGlbSafe1UsgModSts();
    bool isCnvincToOther = (lastUsgMode == sdb::UsgModSts1::UsgModCnvinc) && (usgmod != sdb::UsgModSts1::UsgModCnvinc);

    lastUsgMode = usgmod;

    if (isCnvincToOther) {
        VHALOG.d("HVAC_SEAT_VENTILATION DRVR setCB_VFC_SeatClimaForHmiCenPDC off ");
        setCB_VFC_SeatClimaForHmiCenPDC(sdb::OnOff1::Off);
    }

    PropertyStatus driverStatus = getSeatVentDriverStatus();
    PropertyStatus passStatus = getSeatVentPassStatus();
    PropertyStatus secLeStatus = getSeatVentSecLeStatus(thisPtr);
    PropertyStatus secRiStatus = getSeatVentSecRiStatus(thisPtr);

    if (!hasSendVentTmr && (driverStatus == PropertyStatus::Active || passStatus == PropertyStatus::Active
            || secLeStatus == PropertyStatus::Active || secRiStatus == PropertyStatus::Active)) {
        // 发送固定的通风时长信号
        sendSeatVentTmr();
        hasSendVentTmr = true;
    }

    bool offDriver = (driverStatus == PropertyStatus::NotActive || driverStatus == PropertyStatus::NotAvailable);
    bool offPass = (passStatus == PropertyStatus::NotActive || passStatus == PropertyStatus::NotAvailable);
    bool offSecLe = (secLeStatus == PropertyStatus::NotActive || secLeStatus == PropertyStatus::NotAvailable);
    bool offSecRi = (secRiStatus == PropertyStatus::NotActive || secRiStatus == PropertyStatus::NotAvailable);

    offSeatVentnCheck(thisPtr, offDriver, offPass, offSecLe, offSecRi);

    return driverStatus;
}

PropertyStatus withStatusBySignalsSVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr) {
    VHALOG.d("HVAC_SEAT_VENTILATION PASS cc179[%d], cc13[%d], usgMod[%d],carMod[%d], passAvlSts[%d]",
            SIGNAL.getcarconfig179(), SIGNAL.getcarconfig13(), SIGNAL.getVehModMngtGlbSafe1UsgModSts(), SIGNAL.getVehModMngtGlbSafe1CarModSts1(),
            SIGNAL.getPassSeatVentAvlSts());
    checkSVentCountdown(thisPtr, getSVentPassArea(), mIsSVentPassCounting, mSVentPassStart, mSVentPassEnd);
    return getSeatVentPassStatus();
}

int32_t withValueBySignalsSVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& last) {
    if (isWaiting(HVAC_SEAT_VENTILATION_MSG_1)) {
        VHALOG.d("HVAC_SEAT_VENTILATION DRVR isWaiting HVAC_SEAT_VENTILATION_MSG_1 return.");
        return last;
    }
    sdb::SeatClimaLvl sdblvl = SIGNAL.getDrvrSeatVentnLvlSts();
    auto hallvl = mappingValue(sdblvl, SEAT_CLIMA_OFF);
    g_ventDrvrReqValue = hallvl;
    VHALOG.d("HVAC_SEAT_VENTILATION DRVR value sdblvl : %d , hallvl:%d ", toInt(sdblvl), hallvl);
    return hallvl;
}

int32_t withValueBySignalsSVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& last) {
    if (isWaiting(HVAC_SEAT_VENTILATION_MSG_2)) {
        VHALOG.d("HVAC_SEAT_VENTILATION PASS isWaiting HVAC_SEAT_VENTILATION_MSG_2 return.");
        return last;
    }
    sdb::SeatClimaLvl sdblvl = SIGNAL.getPassSeatVentnLvlSts();
    auto hallvl = mappingValue(sdblvl, SEAT_CLIMA_OFF);
    g_ventPassReqValue = hallvl;
    VHALOG.d("HVAC_SEAT_VENTILATION PASS value sdblvl : %d , hallvl:%d ", toInt(sdblvl), hallvl);
    return hallvl;
}

void onSetPropertySVentDrvr(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& value) {
    VHALOG.d("halOnSetProperty HVAC_SEAT_VENTILATION DRVR value: %d", value);
    if (value != SEAT_CLIMA_OFF &&
        value != SEAT_CLIMA_LEVEL_1 &&
        value != SEAT_CLIMA_LEVEL_2 &&
        value != SEAT_CLIMA_LEVEL_3) {
        VHALOG.d("HVAC_SEAT_VENTILATION DRVR: param invalid");
        return;
    }
    if (mappingValue(SIGNAL.getDrvrSeatVentnLvlSts(), SEAT_CLIMA_OFF) == value) {
        return;
    }

    sendMessage(thisPtr, HVAC_SEAT_VENTILATION_MSG_1, value);
}

void onSetPropertySVentPass(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, const int32_t& value) {
    VHALOG.d("halOnSetProperty HVAC_SEAT_VENTILATION PASS value: %d", value);

    if (value != SEAT_CLIMA_OFF &&
        value != SEAT_CLIMA_LEVEL_1 &&
        value != SEAT_CLIMA_LEVEL_2 &&
        value != SEAT_CLIMA_LEVEL_3) {
        VHALOG.d("HVAC_SEAT_VENTILATION PASS: param invalid");
        return;
    }

    if (mappingValue(SIGNAL.getPassSeatVentnLvlSts(), SEAT_CLIMA_OFF) == value) {
        return;
    }
    clearSVentCountdown(thisPtr, getSVentPassArea());

    sendMessage(thisPtr, HVAC_SEAT_VENTILATION_MSG_2, value);
}

PropertyStatus getSeatVentSecLeStatus(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr)
{
    auto chrSt = SIGNAL.getOnBdChrgrSt();
    if (SIGNAL.carConfigIs(SignalRX::carconfig189, sdb::CarConfig189::_02)) {
        if (SIGNAL.getSeatVentAvlStsRowSecLe() == sdb::StsFd::Functionallimit) {
            return PropertyStatus::NotActive;
        }

        if((SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_01, sdb::CarConfig13::_02, sdb::CarConfig13::_80)) &&
            SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg) &&
            SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm,
                                sdb::CarModSts1::CarModDyno)) {
            return PropertyStatus::Active;
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_03)
            && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno))
        {
            if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg))
            {
                return PropertyStatus::Active;
            }
            else if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModCnvinc) && chrSt == sdb::ChrgrSts1::Chrgn)
            {
                return PropertyStatus::Active;
            }
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04) && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno)
            && SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg, sdb::UsgModSts1::UsgModCnvinc, sdb::UsgModSts1::UsgModActv))
        {
            return PropertyStatus::Active;
        }

        return PropertyStatus::NotActive;
    }
    return PropertyStatus::NotAvailable;
}

PropertyStatus getSeatVentSecRiStatus(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr) {
    auto chrSt = SIGNAL.getOnBdChrgrSt();
    if(SIGNAL.carConfigIs(SignalRX::carconfig189, sdb::CarConfig189::_02))
    {
        if (SIGNAL.getSeatVentAvlStsRowSecRi() == sdb::StsFd::Functionallimit) {
            return PropertyStatus::NotActive;
        }

        if((SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_01, sdb::CarConfig13::_02, sdb::CarConfig13::_80)) &&
            SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg) &&
            SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm,
                                sdb::CarModSts1::CarModDyno)) {
            return PropertyStatus::Active;
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_03)
            && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno))
        {
            if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg))
            {
                return PropertyStatus::Active;
            }
            else if(SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModCnvinc) && chrSt == sdb::ChrgrSts1::Chrgn)
            {
                return PropertyStatus::Active;
            }
        }
        else if(SIGNAL.carConfigIs(SignalRX::carconfig13, sdb::CarConfig13::_04) && SIGNAL.carModeIs(sdb::CarModSts1::CarModNorm, sdb::CarModSts1::CarModDyno)
            && SIGNAL.usgModeIs(sdb::UsgModSts1::UsgModDrvg, sdb::UsgModSts1::UsgModCnvinc, sdb::UsgModSts1::UsgModActv))
        {
            return PropertyStatus::Active;
        }

        return PropertyStatus::NotActive;
    }
    return PropertyStatus::NotAvailable;
}

void setSeatVent(int32_t drvrlvl, int32_t passlvl , int32_t secLelvl, int32_t secRilvl, int32_t heatDrvrlvl, int32_t heatPasslvl , int32_t heatSecLelvl, int32_t heatSecRilvl) {
    VHALOG.d("HVAC_SEAT_VENTILATION  setSeatVent,drvrlvl:%d, passlvl: %d, secLelvl: %d, secRilvl: %d, heatDrvrlvl:%d, heatPasslvl: %d, heatSecLelvl: %d, heatSecRilvl: %d",
            drvrlvl, passlvl, secLelvl, secRilvl, heatDrvrlvl, heatPasslvl, heatSecLelvl, heatSecRilvl);
    OpHmiSeatClima_SetRequestNoReturn climaValue = getCurrOpHmiSeatClima();
    if (drvrlvl != NONE) {
        if (isLeftRudder()) {
            climaValue.hmiSeatClimaHmiSeatVentnForRowFirstLe = (uint8_t)mappingValue(drvrlvl, sdb::SeatClimaLvl::Off);
        } else {
            climaValue.hmiSeatClimaHmiSeatVentnForRowFirstRi = (uint8_t)mappingValue(drvrlvl, sdb::SeatClimaLvl::Off);
        }
    }
    if (passlvl != NONE) {
        if (isLeftRudder()) {
            climaValue.hmiSeatClimaHmiSeatVentnForRowFirstRi = (uint8_t)mappingValue(passlvl, sdb::SeatClimaLvl::Off);
        } else {
            climaValue.hmiSeatClimaHmiSeatVentnForRowFirstLe = (uint8_t)mappingValue(passlvl, sdb::SeatClimaLvl::Off);
        }
    }
    if (secLelvl != NONE) {
        climaValue.hmiSeatClimaHmiSeatVentnForRowSecLe = (uint8_t)mappingValue(secLelvl, sdb::SeatClimaLvl::Off);
    }
    if (secRilvl != NONE) {
        climaValue.hmiSeatClimaHmiSeatVentnForRowSecRi = (uint8_t)mappingValue(secRilvl, sdb::SeatClimaLvl::Off);
    }

    if (heatDrvrlvl != NONE) {
        if (isLeftRudder()) {
            climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstLe = (uint8_t)mappingValue(heatDrvrlvl, sdb::SeatClimaLvl::Off);
        } else {
            climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstRi = (uint8_t)mappingValue(heatDrvrlvl, sdb::SeatClimaLvl::Off);
        }
    }
    if (heatPasslvl != NONE) {
        if (isLeftRudder()) {
            climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstRi = (uint8_t)mappingValue(heatPasslvl, sdb::SeatClimaLvl::Off);
        } else {
            climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstLe = (uint8_t)mappingValue(heatPasslvl, sdb::SeatClimaLvl::Off);
        }
    }
    if (heatSecLelvl != NONE) {
        climaValue.hmiSeatClimaHmiSeatHeatgForRowSecLe = (uint8_t)mappingValue(heatSecLelvl, sdb::SeatClimaLvl::Off);
    }
    if (heatSecRilvl != NONE) {
        climaValue.hmiSeatClimaHmiSeatHeatgForRowSecRi = (uint8_t)mappingValue(heatSecRilvl, sdb::SeatClimaLvl::Off);
    }
    SIGNAL.setHmiSeatClima(climaValue);
}

void offSeatVentnCheck(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, bool offDriver, bool offPass, bool offSecLe, bool offSecRi) {
    VHALOG.d("HVAC_SEAT_VENTILATION  offSeatVentnCheck, offDriver: %d, offPass: %d, offSecLe: %d, offSecRi: %d, mIsPassCounting: %d, mIsSecLeCounting: %d, mIsSecRiCounting: %d",
        offDriver, offPass, offSecLe, offSecRi, mIsSVentPassCounting, mIsSVentSecLeCounting, mIsSVentSecRiCounting);

    if (offDriver || offPass || offSecLe || offSecRi) {
        if (offPass) {
            clearSVentCountdown(thisPtr, getSVentPassArea());
            if (mIsSVentPassCounting) {
                thisPtr->setValue(toInt(getSVentPassArea()), SEAT_CLIMA_OFF, false);
            }
        }
        if (offSecLe) {
            clearSVentCountdown(thisPtr, VehicleAreaSeat::ROW_2_LEFT);
            if (mIsSVentSecLeCounting) {
                thisPtr->setValue(toInt(VehicleAreaSeat::ROW_2_LEFT), SEAT_CLIMA_OFF, false);
            }
        }
        if (offSecRi) {
            clearSVentCountdown(thisPtr, VehicleAreaSeat::ROW_2_RIGHT);
            if (mIsSVentSecRiCounting) {
                thisPtr->setValue(toInt(VehicleAreaSeat::ROW_2_RIGHT), SEAT_CLIMA_OFF, false);
            }
        }
    }
}

static void removeMessage(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, uint32_t msgId) {
    switch (msgId)
    {
    case HVAC_SEAT_VENTILATION_MSG_1:
        mIsWaitingMsg1 = false;
        break;
    case HVAC_SEAT_VENTILATION_MSG_2:
        mIsWaitingMsg2 = false;
        break;
    case HVAC_SEAT_VENTILATION_MSG_3:
        mIsWaitingMsg3 = false;
        break;
    case HVAC_SEAT_VENTILATION_MSG_4:
        mIsWaitingMsg4 = false;
        break;

    }
    thisPtr->removeMsg(msgId);
}

static void sendMessage(ecarx::vhal::core::property::impl::VehiclePropertyHVAC_SEAT_VENTILATION* thisPtr, uint32_t msgId, int32_t value) {
    switch (msgId)
    {
    case HVAC_SEAT_VENTILATION_MSG_1:
        mIsWaitingMsg1 = true;
        g_ventDrvrReqValue = value;
        setDriverSeatVentn(value);
        break;
    case HVAC_SEAT_VENTILATION_MSG_2:
        mIsWaitingMsg2 = true;
        g_ventPassReqValue = value;
        setPassSeatVentn(value);
        break;
    case HVAC_SEAT_VENTILATION_MSG_3:
        mIsWaitingMsg3 = true;
        g_ventSecLeReqValue = value;
        setSecLeSeatVentn(value);
        break;
    case HVAC_SEAT_VENTILATION_MSG_4:
        mIsWaitingMsg4 = true;
        g_ventSecRiReqValue = value;
        setSecRiSeatVentn(value);
        break;

    }
    thisPtr->removeMsg(msgId);
    thisPtr->sendMsg(msgId, HVAC_DELAY);
}